package com.ymttest.database.sqlwapper.shenqisettlement;

import java.math.BigDecimal;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

import com.ymt.core.tool.Logger;
import com.ymt.database.SqlManager;
import com.ymttest.database.model.shenqisettlement.DependentMerchantFeeConfig;

public class DependentMerchantFeeConfigWrapper {

	SqlManager manager;

    public DependentMerchantFeeConfigWrapper() {
        manager = new SqlManager("shenqisettlement");
    }
    
    @SuppressWarnings("unchecked")
	public DependentMerchantFeeConfig selectBySellerId(long sellerId, int payMdoe) {
    	
    	HashMap<String, Object> map = new HashMap<>();
    	
    	map.put("sellerId", sellerId);
    	map.put("payMdoe", payMdoe);
    	
    	List<DependentMerchantFeeConfig> result = manager
                .getSelectResults(
                        "com.ymttest.database.mapping.shenqisettlement.DependentMerchantFeeConfigMapper.selectBySellerId",
                        map);
        manager.commit();
        
		if (result.size() == 0) {
			Logger.comment("platform_fee_setting没有数据");
			
			return null;
		}
		
		return result.get(0);
    }
    
    @SuppressWarnings("unchecked")
	public DependentMerchantFeeConfig selectByPrimaryKey(int payMode) {
    	
    	int id = 0;
    	
    	if (payMode == 0)
    		id = 1;
    	else
    		id = 45;
    	
    	List<DependentMerchantFeeConfig> result = manager
                .getSelectResults(
                        "com.ymttest.database.mapping.shenqisettlement.DependentMerchantFeeConfigMapper.selectByPrimaryKey",
                        id);
        manager.commit();
        
		if (result.size() == 0) {
			Logger.comment("platform_fee_setting没有数据");
			
			return null;
		}
		
		return result.get(0);
    }
    
    public int insert(long sellerId, BigDecimal pay_tax_rate, BigDecimal platform_tax_rate) {
    	
    	int result = 0;
    	
    	DependentMerchantFeeConfig dependentMerchantFeeConfig = new DependentMerchantFeeConfig();
    	
    	Calendar calendar = Calendar.getInstance();
    	
    	calendar.setTime(new Date());
    	calendar.add(Calendar.YEAR, 3);
    	
    	dependentMerchantFeeConfig.setPay_tax_rate(pay_tax_rate);
    	dependentMerchantFeeConfig.setPlatform_tax_rate(platform_tax_rate);
    	dependentMerchantFeeConfig.setSeller_id(sellerId);
    	
    	dependentMerchantFeeConfig.setStart_time(new Date());
    	dependentMerchantFeeConfig.setEnd_time(calendar.getTime());
    	dependentMerchantFeeConfig.setUpdate_time(new Date());
    	dependentMerchantFeeConfig.setAdd_time(new Date());
    	
		result = manager
				.insert("com.ymttest.database.mapping.shenqisettlement.DependentMerchantFeeConfigMapper.insert",
						dependentMerchantFeeConfig);
    	manager.commit();
    	
    	return result;
    }
	
    public static void main(String[] args) {
    	
    	DependentMerchantFeeConfigWrapper test = new DependentMerchantFeeConfigWrapper();
    	
    	System.out.println(test.selectBySellerId(500413235, 1).getPay_tax_rate());
    }
}
